package com.tree.common.util;

import com.tree.mybatisplus.user.entity.User;

/**
 * @ClassName com.demo.nebula.entity
 * Description: <类功能描述>. <br>
 * <p>
 *  在filter或者intercepter中注入，设置user对象
 * </p>
 * @Author tree
 * @Date 2019-05-24 23:12
 * @Version 1.0
 */
public class UserContextHolder {
    private static final ThreadLocal<User> userContextHolder = new ThreadLocal<>();

    public static void setUserInfo(User user){
        userContextHolder.set(user);
    }

    public static User getUserInfo(){
        return userContextHolder.get();
    }

    /**
     * 防止内存泄漏，每次请求完主动remove
     */
    public static void destroy(){
        userContextHolder.remove();
    }
}
